<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('在建项目进度、人员统计表')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<style>
    select {
        padding-top: 3px !important;
    }

    .select-list {
        margin-top: 5px !important;
    }

    .select-list li p {
        width: auto !important;
        margin-top: 7px !important;
    }

    .form-header {
        margin: 10px auto !important;

    }

    .table-striped .table > thead:first-child > tr:first-child > th {
        font-weight: normal;
        font-size: 13px;
        border: 1px solid #cccccc;
        border-top: 1px solid #cccccc !important;
    }

    .text {
        line-height: 34px;
        margin-bottom: 20px;
    }

    .modal-body {
        padding: 15px !important;
    }

    td {
        border: 1px solid #cccccc !important;
        border-top: 1px solid #cccccc !important;

    }

    table {

    }
</style>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="project-form">
                    <div class="col-sm-12">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <p>单位：</p>
                                    <select name="compId" id="compId" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="pro:${userComp}" th:value="${pro.compId}"
                                                th:text="${pro.compName}"></option>
                                    </select>

                                </li>
                                <li>
                                    <p>年份：</p>
                                    <select name="years" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="2020">2020</option>
                                        <option value="2021">2021</option>
                                        <option value="2022">2022</option>
                                        <option value="2023">2023</option>
                                        <option value="2024">2024</option>
                                        <option value="2025">2025</option>
                                    </select>
                                </li>
                                <li>
                                    <p>月份：</p>
                                    <select name="months" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="1">一月</option>
                                        <option value="2">二月</option>
                                        <option value="3">三月</option>
                                        <option value="4">四月</option>
                                        <option value="5">五月</option>
                                        <option value="6">六月</option>
                                        <option value="7">七月</option>
                                        <option value="8">八月</option>
                                        <option value="9">九月</option>
                                        <option value="10">十月</option>
                                        <option value="11">十一月</option>
                                        <option value="12">十二月</option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="operation('search')"><i
                                            class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="operation('reset')"><i
                                            class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped" style="margin-bottom: 10px;">

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()">
                        <i class="fa fa-plus"></i> 新增
                    </a>
                    <a class="btn btn-primary single disabled" onclick="$.operate.edit()">
                        <i class="fa fa-edit"></i> 修改
                    </a>
                    <a class="btn btn-info" onclick="$.modal.openTab('项目管理人员基本配置表','/perSonConfig')">
                        <i class="fa fa-edit"></i> 项目管理人员基本配置表
                    </a>
                    <!--<a class="btn btn-danger" onclick="operation('remove')">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                    <!--</a>-->
                    <a class="btn btn-warning" onclick="exportData()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <table id="proProgress-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var prefix = ctx + 'proProgress';
    var value;
    var proProgress_options;
    $(function () {
        proProgress_options = {
            url: prefix + '/list',
            uniqueId: "id",
            id: 'proProgress-table',
            createUrl: prefix + "/add",
            removeUrl: prefix + "/remove",
            updateUrl: prefix + "/edit/{id}",
            modalName: "在建项目进度、人员统计表",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            pagination: true,
            pageSize: 5,
            showExport: true,      //是否显示导出
            onLoadSuccess: function (data) {
                var biaozhun_index = -3;
                var chayi_index = -1;
                var json;
                var s = [];
                var total_area_sum = [];
                var standard_sum = [];
                var totalNum = 0;
                for (var i in data.rows) {
                    if (data.rows[i].compName != undefined) {
                        s.push(data.rows[i]);
                        total_area_sum.push(data.rows[i].totalArea);
                    }

                }
                for (var i in data.rows) {
                    biaozhun_index = biaozhun_index + 3;
                    chayi_index = chayi_index + 3;
                    $.ajax({
                        url: prefix + '/findPersonNum',
                        data: {
                            total_area: total_area_sum[i]
                        },
                        async: false,
                        success: function (data) {
                            console.log(data);
                            if (data.data != null) {
                                standard_sum.push(data.data);
                                totalNum = standard_sum[i].xmjl + standard_sum[i].jsfzr + standard_sum[i].aqzg + standard_sum[i].aqy + standard_sum[i].zlzg + standard_sum[i].zjy + standard_sum[i].yjsgy + standard_sum[i].erjsgy + standard_sum[i].sjsgy + standard_sum[i].zly + standard_sum[i].dg + standard_sum[i].clzg + standard_sum[i].cly + standard_sum[i].lzy + standard_sum[i].scjl;
                            }


                        }
                    });

                    json = [{
                        index: biaozhun_index,
                        row: {
                            peizhi: "标准",
                            compName: s[i].compName,
                            months: s[i].months,
                            years: s[i].years,
                            proName: s[i].proName,
                            proFormat: s[i].proFormat,
                            currentProgress: s[i].currentProgress,
                            groundArea: s[i].groundArea,
                            undergroundArea: s[i].undergroundArea,
                            totalArea: s[i].totalArea,
                            id: s[i].id,
                            xmjlNum: standard_sum[i].xmjl,
                            jsfzrNum: standard_sum[i].jsfzr,
                            aqzgNum: standard_sum[i].aqzg,
                            aqyNum: standard_sum[i].aqy,
                            zlzgNum: standard_sum[i].zlzg,
                            zjyNum: standard_sum[i].zjy,
                            yjsgyNum: standard_sum[i].yjsgy,
                            erjsgyNum: standard_sum[i].erjsgy,
                            sjsgyNum: standard_sum[i].sjsgy,
                            zlyNum: standard_sum[i].zly,
                            dgNum: standard_sum[i].dg,
                            clzgNum: standard_sum[i].clzg,
                            clyNum: standard_sum[i].cly,
                            lzyNum: standard_sum[i].lzy,
                            scjlNum: standard_sum[i].scjl,
                            totalNum: totalNum,
                            remarks: s[i].remarks

                        }
                    }, {
                        index: chayi_index, row: {
                            peizhi: "差异",
                            xmjlNum: s[i].xmjlNum - standard_sum[i].xmjl,
                            jsfzrNum: s[i].jsfzrNum - standard_sum[i].jsfzr,
                            aqzgNum: s[i].aqzgNum - standard_sum[i].aqzg,
                            aqyNum: s[i].aqyNum - standard_sum[i].aqy,
                            zlzgNum: s[i].zlzgNum - standard_sum[i].zlzg,
                            zjyNum: s[i].zjyNum - standard_sum[i].zjy,
                            yjsgyNum: s[i].yjsgyNum - standard_sum[i].yjsgy,
                            erjsgyNum: s[i].erjsgyNum - standard_sum[i].erjsgy,
                            sjsgyNum: s[i].sjsgyNum - standard_sum[i].sjsgy,
                            zlyNum: s[i].zlyNum - standard_sum[i].zly,
                            dgNum: s[i].dgNum - standard_sum[i].dg,
                            clzgNum: s[i].clzgNum - standard_sum[i].clzg,
                            clyNum: s[i].clyNum - standard_sum[i].cly,
                            lzyNum: s[i].lzyNum - standard_sum[i].lzy,
                            scjlNum: s[i].scjlNum - standard_sum[i].scjl,
                            totalNum: s[i].totalNum - totalNum
                        }
                    }]
                    $('#proProgress-table').bootstrapTable('insertRow', json[0]);
                    $('#proProgress-table').bootstrapTable('insertRow', json[1]);

                }
                var num = 0;
                var fieldArry = new Array("proFormat2", "checkbox", "compName", "months", "years", "proName", "proFormat",
                    "currentProgress", "groundArea", "undergroundArea", "totalArea", "id", "remarks");
                for (var i = 0; i < data.rows.length; i++) {
                    for (var j = 0; j < fieldArry.length; j++) {
                        $('#proProgress-table').bootstrapTable('mergeCells', {
                            index: num,
                            field: fieldArry[j],
                            colspan: 1,
                            rowspan: 3
                        });

                    }
                    num = num + 3;
                }

            },
            columns: [

                [
                    {
                        field: 'checkbox',
                        checkbox: true,
                        rowspan: 2,
                        valign: "middle",
                        align: "center",

                    },
                    {
                        field: 'id',
                        title: '主键',
                        rowspan: 2,
                        valign: "middle",
                        align: "center",
                        visible: false

                    },
                    {
                        field: 'compName',
                        title: '区域',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'months',
                        title: '月份',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'years',
                        title: '年份',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'proName',
                        title: '项目名称',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },

                    {
                        field: 'proFormat',
                        title: '项目业态',
                        rowspan: 2,
                        valign: "middle",
                        align: "center",
                        formatter: function (value, row, index) {
                            return ' <div style="width:200px;">' + value + ' </div>';
                        }
                    },
                    {
                        field: 'currentProgress',
                        title: '当前进度',
                        rowspan: 2,
                        valign: "middle",
                        align: "center",
                        formatter: function (value, row, index) {
                            return ' <div style="width:200px;">' + value + ' </div>';
                        }
                    },
                    {
                        title: '建筑面积（㎡）',
                        rowspan: 1,
                        colspan: 3,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'peizhi',
                        title: '配置',
                        align: "center",
                        valign: "middle",
                        rowspan: 2,
                        formatter: function (value, row, index) {
                            if (value == undefined) {
                                value = '实际'
                            }
                            return value
                        }

                    },
                    {
                        field: 'xmjlNum',
                        title: '项目经理',
                        rowspan: 2,
                        valign: "middle",
                        align: "center",

                    },
                    {
                        field: 'jsfzrNum',
                        title: '技术负责人',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'scjlNum',
                        title: '生产经理',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'aqzgNum',
                        title: '安全主管',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'aqyNum',
                        title: '安全员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'zlzgNum',
                        title: '质量主管',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'zjyNum',
                        title: '质检员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'yjsgyNum',
                        title: '一级施工员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'erjsgyNum',
                        title: '二级施工员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'sjsgyNum',
                        title: '三级施工员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'zlyNum',
                        title: '资料员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'dgNum',
                        title: '电工',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'clzgNum',
                        title: '材料主管',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'clyNum',
                        title: '材料员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'lzyNum',
                        title: '劳资员',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'totalNum',
                        title: '合计人数',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'remarks',
                        title: '备注',
                        rowspan: 2,
                        valign: "middle",
                        align: "center"
                    }

                ],
                [
                    {
                        field: 'groundArea',
                        title: '地上面积',
                        rowspan: 1,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'undergroundArea',
                        title: '地下面积',
                        rowspan: 1,
                        valign: "middle",
                        align: "center"
                    },
                    {
                        field: 'totalArea',
                        title: '合计面积',
                        rowspan: 1,
                        valign: "middle",
                        align: "center"
                    },

                ],
            ]
        }
        $.table.init(proProgress_options);
    })

    function operation(data) {
        if (data == 'remove') {
            $.operate.removeAll();
            $(".layui-layer-btn0").click(function () {
                //sum();
            })
        }
        if (data == 'search') {
            $.table.search();
            //sum();
        }
        if (data == 'reset') {
            $.form.reset();
            //sum();
        }
    }

    function exportEmpChange() {
        $("#proProgress-table").tableExport({
            exportDataType: "all",
            type: 'excel',
            fileName: '在建项目进度、人员统计表',

        });
    }

    function exportData() {
        var years = $("#years").val();
        var months = $("#months").val();
        if (years == '' || months == '') {
            alert("先选择导出日期");
        } else {
            $.operate.exportData("rlExportData/exportProData?years= " + years + "&months=" + months, "项目进度人员统计表");
            $(".btn-white").click();
        }
    }

</script>
</body>
</html>